<%-- 
    Document   : QuanLySanPhamSubpage
    Created on : May 18, 2011, 12:38:20 AM
    Author     : ToanNhan
--%>

<%@page import="Pojos.SanPham"%>
<%@page import="Pojos.DanhMucSanPham"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../js/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="script/QuanLySanPham.js"></script>
<center>
    <form action="QuanLySanPham.jsp" method="post" name="submitForm">
        <input type="hidden" id="action" name="action" value=""/>
        <div class="box" style="height: 70px;width:90%; text-align: center; padding: 10px 20px 10px 20px; margin: 10px 0px 0px 0px;">
            <div style="float: left; width:500px; text-align: left; margin: 5px 0px 5px 0px;">
                <table width="100%">
                    <tr bgcolor="bisque">
                        <td width="200px">
                            Chọn danh mục:
                        </td>
                        <td>
                            <select name="maDanhMuc" id="danhMucSanPham">
                                <%
                                            String maDanhMuc = "DM01";
                                            if (request.getParameter("maDanhMuc") != null) {
                                                maDanhMuc = request.getParameter("maDanhMuc");
                                            }
                                            List<DanhMucSanPham> lstDanhMucSanPham = (List<DanhMucSanPham>) request.getAttribute("danhSachDanhMuc");
                                            for (DanhMucSanPham dm : lstDanhMucSanPham) {
                                %>
                                <option <%if (dm.getMaDanhMuc().compareTo(maDanhMuc) == 0) {
                                                                                    out.print("selected=\"true\"");
                                                                                }%> value="<%=dm.getMaDanhMuc()%>"><%=dm.getTenDanhMuc()%></option>
                                <%
                                            }
                                %>
                            </select>
                        </td>
                    </tr>
                    <tr bgcolor="bisque">
                        <td>
                            Nhập tên hoặc mã sản phẩm:
                        </td>
                        <td>
                            <input type="text" name="txtSearch" id="txtSearch" style="width: 200px;" />
                            <input type="submit" id="command" name="command" value="search"/>
                        </td>
                    </tr>
                </table>
            </div>
            <div style="float:right; width:180px; text-align: right; padding: 10px; margin: 5px 0px 5px 0px;">
                <a style="margin-right: 3px;" href="/WebsiteBanHang/Admin/ThemSanPham.jsp" id="toolbarNew">
                    <img alt="Thêm mới" width="32px" height="32px" src="/WebsiteBanHang/images/icon-new.png" />
                </a>
                <a href="#" style="margin-right: 3px;" id="toolbarEdit"><img alt="Chỉnh sửa" width="32px" height="32px" src="/WebsiteBanHang/images/icon-edit.png" /></a>
                <img height="30px" width="2px" src="/WebsiteBanHang/images/divider.jpg"/>
                <a style="margin-right: 3px;" href="#" id="toolbarConHang"><img alt="Còn hàng" width="32px" height="32px" src="/WebsiteBanHang/images/cart_icon.jpg" /></a>
                <a style="margin-right: 3px;" href="#" id="toolbarHetHang"><img alt="Hết hàng" width="32px" height="32px" src="/WebsiteBanHang/images/nocart_icon.jpg" /></a>

            </div>
        </div>
        <div class="box" style="clear:both; width:90%; text-align: center; padding: 20px; margin: 10px 0px 10px 0px;">
            <div style="width: 100%;">
                <table width="100%" border="1px">
                    <tr bgcolor="blue">
                        <td width="20px">
                            &nbsp;
                        </td>
                        <td width="100px">
                            <font color="white">Mã sản phẩm</font>
                        </td>
                        <td width="250px">
                            <font color="white">Tên sản phẩm</font>
                        </td>
                        <td width="125px">
                            <font color="white">Hình sản phẩm</font>
                        </td>
                        <td width="75px">
                            <font color="white">Tình trạng</font>
                        </td>
                        <td width="150px">
                            <font color="white">Giá bán</font>
                        </td>
                    </tr>
                    <%
                                List<SanPham> lstSanPham = (List<SanPham>) request.getAttribute("danhSachSanPham");
                                boolean color = false;
                                for (SanPham sp : lstSanPham) {
                                    if (color == false) {
                                        color = true;
                    %>
                    <tr>
                        <%} else {
                                                                color = false;%>
                    <tr bgcolor="bisque">
                        <%}%>
                        <td>
                            <input type="checkbox" name="chkMaSanPham" value="<%=sp.getMaSanPham()%>"/>
                        </td>
                        <td>
                            <%=sp.getMaSanPham()%>
                        </td>
                        <td>
                            <%=sp.getTenSanPham()%>
                        </td>
                        <td>
                            <img alt="<%=sp.getMaSanPham()%>" src="/WebsiteBanHang<%=sp.getHinhSanPham()%>" height="50px" width="50px"/>
                        </td>
                        <td>
                            <%
                                                                if (sp.getTinhTrang() == SanPham.CON_HANG) {
                                                                    out.print("Còn hàng");
                                                                } else {
                                                                    out.print("Hết hàng");
                                                                }
                            %>
                        </td>
                        <td>
                            <%=sp.getGiaBan()%> VNĐ
                        </td>
                    </tr>
                    <%
                                }
                                request.setAttribute("danhSachSanPham", null);
                    %>
                </table>
            </div>
            <div style="width: 100%; text-align: center; margin-top: 5px;">
                <center>
                <table>
                    <tr>
                        <td align="center">
                            Hiển thị:   <select name="soLuongTrenTrang" id="soLuongTrenTrang">
                                <%  int soLuongTrenTrang = 20;
                                            if (request.getParameter("soLuongTrenTrang") != null) {
                                                soLuongTrenTrang = Integer.valueOf(request.getParameter("soLuongTrenTrang"));
                                            }
                                %>
                                <option <%if (soLuongTrenTrang == 5) {
                                                out.print("selected=\"true\"");
                                            }%> value="5">5</option>
                                <option <%if (soLuongTrenTrang == 10) {
                                                out.print("selected=\"true\"");
                                            }%> value="10">10</option>
                                <option <%if (soLuongTrenTrang == 15) {
                                                out.print("selected=\"true\"");
                                            }%> value="15">15</option>
                                <option <%if (soLuongTrenTrang == 20) {
                                                out.print("selected=\"true\"");
                                            }%> value="20">20</option>
                                <option <%if (soLuongTrenTrang == 25) {
                                                out.print("selected=\"true\"");
                                            }%> value="25">25</option>
                                <option <%if (soLuongTrenTrang == 30) {
                                                out.print("selected=\"true\"");
                                            }%> value="30">30</option>
                                <option <%if (soLuongTrenTrang == 50) {
                                                out.print("selected=\"true\"");
                                            }%> value="50">50</option>
                                <option <%if (soLuongTrenTrang == 100) {
                                                out.print("selected=\"true\"");
                                            }%> value="100">100</option>
                                <option <%if (soLuongTrenTrang == -1) {
                                                out.print("selected=\"true\"");
                                            }%> value="-1">All</option>
                            </select></td>
                            <%
                                        int trangHienTai = 1;
                                        if (request.getParameter("trangHienTai") != null) {
                                            trangHienTai = Integer.valueOf(request.getParameter("trangHienTai"));
                                        }
                                        int tongSoTrang = 1;
                                        if (request.getAttribute("tongSoTrang") != null) {
                                            tongSoTrang = (Integer)request.getAttribute("tongSoTrang");
                                        }
                                        if (trangHienTai == 1) {
                            %>
                            <td>
                                <img src="/WebsiteBanHang/images/GoFirst.png" align="middle" alt="First" height="32" width="64"/>
                            </td>
                            <td>
                                <img src="/WebsiteBanHang/images/GoPrevious.png" align="middle" alt="First" height="32" width="64"/>
                            </td>
                            <%                                    } else {
                            %>
                            <td>
                                <a href="/WebsiteBanHang/Admin/QuanLySanPham.jsp?trangHienTai=1&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                    <img src="/WebsiteBanHang/images/GoFirst.png" align="middle" alt="First" height="32" width="64"/>
                                </a>
                            </td>
                            <td>
                                <a href="/WebsiteBanHang/Admin/QuanLySanPham.jsp?trangHienTai=<%out.print((trangHienTai - 1));%>&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                    <img src="/WebsiteBanHang/images/GoPrevious.png" align="middle" alt="First" height="32" width="64"/>
                                </a>
                            </td>
                            
                            <%
                                        }
                            %><td bgcolor="bisque"><%
                                        
                                        for (int i = 1; i <= tongSoTrang; i++) {
                                            out.print("&nbsp;");
                                            if (i != trangHienTai) {
                            %>
                                                <a href="/WebsiteBanHang/Admin/QuanLySanPham.jsp?trangHienTai=<%=i%>&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                                    <%=i%>
                                                </a>
                        <%                                }
                                            else{
                                                out.print(i);
                                            }
                                    }
                                    out.print("&nbsp;");
                        %>
                            </td>
                            <%
                            if (trangHienTai == tongSoTrang) {
                            %>
                            <td>
                                <img src="/WebsiteBanHang/images/GoNext.png" align="middle" alt="Next" height="32" width="64"/>
                            </td>
                            <td>
                                <img src="/WebsiteBanHang/images/GoLast.png" align="middle" alt="Last" height="32" width="64"/>
                            </td>
                            <%                                    } else {
                            %>
                            <td>
                                <a href="/WebsiteBanHang/Admin/QuanLySanPham.jsp?trangHienTai=<%=(trangHienTai + 1)%>&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                    <img src="/WebsiteBanHang/images/GoNext.png" align="middle" alt="Next" height="32" width="64"/>
                                </a>
                            </td>
                            <td>
                                <a href="/WebsiteBanHang/Admin/QuanLySanPham.jsp?trangHienTai=<%=tongSoTrang%>&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                    <img src="/WebsiteBanHang/images/GoLast.png" align="middle" alt="Last" height="32" width="64"/>
                                </a>
                            </td>
                            <%}%>
                    </tr>
                </table></center>
            </div>
        </div>
    </form>
</center>